/*
 * @Description: 文件描述
 * @Author: 1+
 * @Date: 2024-03-18 08:43:38
 * @LastEditors: 1+
 * @LastEditTime: 2024-08-29 17:15:23
 */
import { getLocalStorage } from '@/utils'
import ChartList from '@/packages/components/Charts'
import DecorateList from '@/packages/components/Decorates'
import InformationList from '@/packages/components/Informations'
import TableList from '@/packages/components/Tables'
import PhotoList from '@/packages/components/Photos'
import IconList from '@/packages/components/Icons'

const state = {
  packagesList: {
    Charts: ChartList,
    Tables: TableList,
    Informations: InformationList,
    Decorates: DecorateList,
    // Photos: PhotoList,
    // Icons: IconList
  },
  // 是否重置当前画布位置
  rePositionCanvas: false,
  // 图层控制
  layers: true,
  // 图表组件
  charts: true,
  // 图表配置组件
  configs: true,
  ...getLocalStorage('layout')
}

const mutations = {
  setItem (state, { key, value, computedScale = true }) {
    state[key] = value
    // 存储本地
    localStorage.setItem('layout', JSON.stringify(state))
    // 这里需要标记重置画布位置
    state.rePositionCanvas = true
    // 重新计算拖拽区域缩放比例
    if (computedScale) {
      setTimeout(() => {
        this.dispatch('chartEdit/computedScale')
      }, 500)
    }
  },
}

const actions = {
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
